from django.shortcuts import render
from rest_framework.authentication import SessionAuthentication
from rest_framework.decorators import action
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView

import logging

from rest_framework.viewsets import ViewSet

logger = logging.getLogger(__name__)


class AuthAPIView(APIView):
    authentication_classes = [
        # BasicAuthentication,
        # SessionAuthentication,
    ]
    permission_classes = [IsAuthenticated, ]

    def get(self, request, ):
        logger.info('get')
        response = Response()
        return response


class AuthViewSet(ViewSet):
    authentication_classes = [
        # BasicAuthentication,
        SessionAuthentication,
    ]
    permission_classes = [
        IsAuthenticated,
    ]

    def get_authenticators(self):
        if self.action == 'no_auth':
            return []
        return [auth() for auth in self.authentication_classes]

    def get_permissions(self):
        if self.action == 'no_auth':
            return []
        return [permission() for permission in self.permission_classes]

    @action(methods=['post'], detail=False)
    def no_auth(self):
        response = Response()
        return response
